package com.jt.sso.controller;

import com.jt.sso.util.JwtUtils;
import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class AuthController {
    @GetMapping("/auth/info")
    public Map<String,Object> getAuthentication(String token){
        //1. 解析token
        System.out.println("token==="+token);
        Claims claims = JwtUtils.getClaimsFromToken(token);
        System.out.println(claims);
        //2. 判断token有效期
//        boolean flag = claims.getExpiration().before(new Date());
        //3. 获取用户名
//        String username = (String) claims.get("username");
        //4. 获取用户权限
//        List<String> list=(List<String>) claims.get("authorities");
        //5. 封装数据并返回
//        Map<String,Object> map=new HashMap<>();
//        map.put("expired",flag);
//        map.put("username",username);
//        map.put("authorities",list);
        return claims;
    }
}
